//package cn.apiManager.interceptor;
//
//import java.io.PrintWriter;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.apache.commons.lang3.StringUtils;
//import org.apache.log4j.Logger;
//import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
//
//import cn.apiManager.common.Constant;
//import cn.apiManager.utils.CookieUtil;
//
//
///**
// * @desc	会话拦截器
// * @time	
// */
//public class SessionInterceptor extends HandlerInterceptorAdapter{
//	
//	private static final Logger logger = Logger.getLogger(SessionInterceptor.class);
//	
//	/**
//	 * 处理时间  线程绑定
//	 */
//	private ThreadLocal<Long> dealTimeThradeLocal = new ThreadLocal<Long>();
//	
//	/**
//	 * 请求前进行会话校验
//	 */
//	@Override
//	public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
//		long startTime = System.currentTimeMillis();
//		dealTimeThradeLocal.set(startTime);
//		String path = request.getRequestURI();
//		String basePath = request.getContextPath();
//		String url = path.substring(basePath.length(), path.length());
//
//		
////		if(!isStaticFile(url) && !url.contains("api") && !url.equals("/") && !url.contains("/login") && !url.contains("/registerSave")){
////			String userName = CookieUtil.getCookie(request, response, Constant.COOKIE_LOGIN_NAME_KEY);
////			if(StringUtils.isBlank(userName)){
////				// 未登录
////				PrintWriter out = response.getWriter();
////				out.println("<html><script type='text/javascript'>window.open('"+basePath+"/','_top')</script></html>");
////				out.flush();
////				return false;
////			}
////		}
//		
//		return true;
//	}
//	
//	
//	public boolean isStaticFile(String url){
//		if(!StringUtils.isEmpty(url)){
//			// 静态文件
//			int index = url.lastIndexOf(".");
//			String postFix = null;
//			if(index > -1){
//				postFix = url.substring(index);
//			}
//			
//			if(!StringUtils.isEmpty(postFix)){
//				// 静态文件默认处理
//				return true;
//			}
//		}
//		
//		return false;
//	}
//	
//	@Override
//	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//		if(!isStaticFile(request.getRequestURI())){
//			long endTime = System.currentTimeMillis();
//			long starTime = dealTimeThradeLocal.get();
//			logger.info("本次请求["+request.getRequestURI()+"]处理时间："+(endTime-starTime)+"ms");
//		}
//		
//		super.afterCompletion(request, response, handler, ex);
//	}
//	
//}
